package com.pool.objects;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;

public class Table {

	public static double[] dimensions = new double[] {2.7, 1.35};
	private Ball[] balls = new Ball[16];
	private int[] currMouseCoords = null;
	
	public Table() {
		balls[0] = new Ball(BallColor.WHITE);
		
		balls[1] = new Ball(BallColor.YELLOW);
		balls[2] = new Ball(BallColor.BLUE);
		balls[3] = new Ball(BallColor.RED);
		balls[4] = new Ball(BallColor.PURPLE);
		balls[5] = new Ball(BallColor.ORANGE);
		balls[6] = new Ball(BallColor.GREEN);
		balls[7] = new Ball(BallColor.BROWN);
		
		balls[8] = new Ball(BallColor.BLACK);
		
		balls[9] = new Ball(BallColor.YELLOW_AND_WHITE);
		balls[10] = new Ball(BallColor.BLUE_AND_WHITE);
		balls[11] = new Ball(BallColor.RED_AND_WHITE);
		balls[12] = new Ball(BallColor.PURPLE_AND_WHITE);
		balls[13] = new Ball(BallColor.ORANGE_AND_WHITE);
		balls[14] = new Ball(BallColor.GREEN_AND_WHITE);
		balls[15] = new Ball(BallColor.BROWN_AND_WHITE);
	}
	
	public void paint(Graphics g, Rectangle r) {
		double scaleFactor;
		int[] dimmensions, displacement;
        int size, halfSize;
		
		if (r.width / dimensions[0] < r.height / dimensions[1]) {
		    scaleFactor = r.width / dimensions[0];
            displacement = new int[] {0, (int) ((r.height - dimensions[1] * scaleFactor) / 2)};
            dimmensions = new int[] {r.width, r.height - 2 * displacement[1]};
		} else {
            scaleFactor = r.height / dimensions[1];
            displacement = new int[] {(int) ((r.width - dimensions[0] * scaleFactor) / 2), 0};
            dimmensions = new int[] {r.width - 2 * displacement[0], r.height};
		}
		
		// TODO: Fix crude hot-fix
		size = (int) (Ball.radius * 2 * scaleFactor);
		halfSize = size / 2;
		
		// TODO: Input real texture
		g.setColor(new Color(0, 255, 0));
		g.fillRect(displacement[0],
		           displacement[1],
		           dimmensions[0],
		           dimmensions[1]);
		
		for (int i = 0; i < balls.length; i++)
			balls[i].paint(g, size, halfSize, displacement, dimmensions);
	}
	
	public void mouseEvent(int[] org, int[] curr) {
		
	}
	
}
